//
//  MainViewController.swift
//  Swift-SinaWeibo
//
//  Created by 陈高健 on 15/12/12.
//  Copyright © 2015年 陈高健. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    //必选属性
    let mainTabBar = MainTabBar()
    
    @objc private func composeBtnDidClick() {
            print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        print(tabBar.classForCoder)
        
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        setValue(mainTabBar, forKey: "tabBar")
        //classForCoder 对象的类的字符串形式
        print(tabBar.classForCoder)
        //添加子视图控制器
        addChildViewControllers()

    }
    
    //private表示只能在本类中进行访问
    private func addChildViewControllers() {
        
        //HomeTableViewController() 需要修改
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    

    private func addChildViewController(vc: UIViewController,title: String,imageName: String) {
        
        
        let nav = UINavigationController(rootViewController: vc)
        //        title = "首页"
        //        nav.title = "首页"
        vc.title = title
        //设置图片
        vc.tabBarItem.image = UIImage(named: imageName)
        //        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        //在swift中 self 可以省略
        self.addChildViewController(nav)
    }
    
}
